﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SuperJoe.Framework.Caching
{
    public static class CacheManager
    {
        private static ICache cache = null;

        public static void Init(string connectionString)
        {
            cache = new SERedisCache(connectionString);
        }

        public static ICache Cache
        {
            get
            {
                CheckCacheIsInitialized();

                return cache;
            }
        }

        public static IRedisCache RedisCache
        {
            get
            {
                CheckCacheIsInitialized();

                return (IRedisCache)cache;
            }
        }

        private static void CheckCacheIsInitialized()
        {
            if (cache == null)
            {
                throw new CacheNotInitException("Cache未初始化，请先调用Init方法。");
            }
        }
    }
}
